<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>操作系统实践-实现一个fat12文件系统 | hatena</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="1. 基本信息   姓名 学号 班级 是否抄袭 是否分组    yyh 2021****117 计算2114 否 否   实现了哪些功能（已实现，并且测试正确的打勾）    打印当前目录下所有文件和目录名，类似于ls简易版    打印文件&#x2F;目录的文件控制块    打印整个文件分配表    切换目录，类似于cd功能    创建文件、删除文件    创建目录、删除文件    cat命令查看文">
<meta property="og:type" content="article">
<meta property="og:title" content="操作系统实践-实现一个fat12文件系统">
<meta property="og:url" content="https://gitee.com/lanceluot/blog.git/2024/04/30/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E5%AE%9E%E8%B7%B5-%E5%AE%9E%E7%8E%B0%E4%B8%80%E4%B8%AAfat12%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F/index.html">
<meta property="og:site_name" content="hatena">
<meta property="og:description" content="1. 基本信息   姓名 学号 班级 是否抄袭 是否分组    yyh 2021****117 计算2114 否 否   实现了哪些功能（已实现，并且测试正确的打勾）    打印当前目录下所有文件和目录名，类似于ls简易版    打印文件&#x2F;目录的文件控制块    打印整个文件分配表    切换目录，类似于cd功能    创建文件、删除文件    创建目录、删除文件    cat命令查看文">
<meta property="og:locale" content="zn_CN">
<meta property="og:image" content="https://gitee.com/blog/img/image-20230623225929061.png">
<meta property="og:image" content="https://gitee.com/blog/img/image-20230623230722029.png">
<meta property="og:image" content="https://gitee.com/blog/img/image-20230623222255133.png">
<meta property="og:image" content="https://gitee.com/blog/img/image-20230623222559771.png">
<meta property="og:image" content="https://gitee.com/blog/img/image-20230623223601753.png">
<meta property="og:image" content="https://gitee.com/blog/img/image-20230623223639776.png">
<meta property="og:image" content="https://gitee.com/blog/img/image-20230623214228340.png">
<meta property="og:image" content="https://gitee.com/blog/img/image-20230623214429206.png">
<meta property="og:image" content="https://gitee.com/blog/img/image-20230623214937354.png">
<meta property="og:image" content="https://gitee.com/blog/img/image-20230623215111176.png">
<meta property="og:image" content="https://gitee.com/blog/img/image-20230623215053138.png">
<meta property="og:image" content="https://gitee.com/blog/img/image-20230623214750670.png">
<meta property="og:image" content="https://gitee.com/blog/img/image-20230623214725323.png">
<meta property="og:image" content="https://gitee.com/blog/img/image-20230623225853302.png">
<meta property="article:published_time" content="2024-04-30T15:57:51.000Z">
<meta property="article:modified_time" content="2024-05-01T05:42:28.345Z">
<meta property="article:author" content="myself">
<meta property="article:tag" content="操作系统">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/blog/img/image-20230623225929061.png">
  
    <link rel="alternate" href="/blog/atom.xml" title="hatena" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/blog/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/blog/css/style.css">

  
    
<link rel="stylesheet" href="/blog/fancybox/jquery.fancybox.min.css">

  
  
<meta name="generator" content="Hexo 6.3.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/blog/" id="logo">hatena</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"><span class="fa fa-bars"></span></a>
        
          <a class="main-nav-link" href="/blog/">Home</a>
        
          <a class="main-nav-link" href="/blog/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
        
          <a class="nav-icon" href="/blog/atom.xml" title="RSS Feed"><span class="fa fa-rss"></span></a>
        
        <a class="nav-icon nav-search-btn" title="Suche"><span class="fa fa-search"></span></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Suche"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="https://gitee.com/lanceluot/blog.git"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-操作系统实践-实现一个fat12文件系统" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog/2024/04/30/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E5%AE%9E%E8%B7%B5-%E5%AE%9E%E7%8E%B0%E4%B8%80%E4%B8%AAfat12%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F/" class="article-date">
  <time class="dt-published" datetime="2024-04-30T15:57:51.000Z" itemprop="datePublished">2024-04-30</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="p-name article-title" itemprop="headline name">
      操作系统实践-实现一个fat12文件系统
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h1 id="1-基本信息"><a href="#1-基本信息" class="headerlink" title="1. 基本信息"></a>1. 基本信息</h1><table>
<thead>
<tr>
<th align="center">姓名</th>
<th align="center">学号</th>
<th align="center">班级</th>
<th align="center">是否抄袭</th>
<th align="center">是否分组</th>
</tr>
</thead>
<tbody><tr>
<td align="center">yyh</td>
<td align="center">2021****117</td>
<td align="center">计算2114</td>
<td align="center">否</td>
<td align="center">否</td>
</tr>
</tbody></table>
<p><strong>实现了哪些功能（已实现，并且测试正确的打勾）</strong></p>
<ul>
<li><p><input checked="" disabled="" type="checkbox"> 
打印当前目录下所有文件和目录名，类似于<code>ls</code>简易版</p>
</li>
<li><p><input checked="" disabled="" type="checkbox"> 
打印文件&#x2F;目录的文件控制块</p>
</li>
<li><p><input checked="" disabled="" type="checkbox"> 
打印整个文件分配表</p>
</li>
<li><p><input checked="" disabled="" type="checkbox"> 
切换目录，类似于<code>cd</code>功能</p>
</li>
<li><p><input checked="" disabled="" type="checkbox"> 
创建文件、删除文件</p>
</li>
<li><p><input checked="" disabled="" type="checkbox"> 
创建目录、删除文件</p>
</li>
<li><p><input checked="" disabled="" type="checkbox"> 
cat命令查看文件(额外实现)</p>
  <span id="more"></span></li>
</ul>
<h1 id="2-功能1-ls"><a href="#2-功能1-ls" class="headerlink" title="2. 功能1 (ls)"></a>2. 功能1 (ls)</h1><h2 id="2-1-实现思路及伪代码"><a href="#2-1-实现思路及伪代码" class="headerlink" title="2.1 实现思路及伪代码"></a>2.1 实现思路及伪代码</h2><p>思路：</p>
<p>打印当前目录下的子文件和文件夹，根据fat12文件系统的特点，我们可以访问FCB表，然后再根据FCB表的蔟号，一边到数据区去访问数据一边去fat表查找下一个蔟号，然后继续访问数据区，如果蔟号不为零，继续读取蔟号和数据区直到蔟号为0xfff或其他已分配标识符</p>
<p>伪代码：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">读取当前目录的文件控制块，</span><br><span class="line">    读取文件控制块的蔟号，</span><br><span class="line">    根据蔟号访问fat表和数据区，</span><br><span class="line">    <span class="keyword">while</span>(蔟号不为结束符时)&#123;</span><br><span class="line">        继续访问数据区，</span><br><span class="line">            然后访问下一个蔟号；</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>



<h2 id="2-2-完整的源代码"><a href="#2-2-完整的源代码" class="headerlink" title="2.2 完整的源代码"></a>2.2 完整的源代码</h2><p>ls函数代码：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">void</span> *<span class="title function_">ls</span><span class="params">(<span class="type">const</span> <span class="type">char</span> *dir)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="type">int</span> cnt = <span class="number">0</span>;</span><br><span class="line">    <span class="type">char</span> dir_name[<span class="number">8</span>];</span><br><span class="line">    <span class="built_in">strcpy</span>(dir_name, dir);</span><br><span class="line">    <span class="keyword">if</span> (<span class="built_in">strlen</span>(dir_name) == <span class="number">0</span> || dir_name[<span class="number">0</span>] == <span class="string">&#x27;-&#x27;</span>)</span><br><span class="line">    &#123; <span class="comment">// 说明不带参数，打印当前目录下</span></span><br><span class="line">        fatmp.f[<span class="number">0</span>] = currdir.DIR_FstClus[<span class="number">0</span>];</span><br><span class="line">        fatmp.f[<span class="number">1</span>] = currdir.DIR_FstClus[<span class="number">1</span>];</span><br><span class="line">        <span class="type">int</span> next = read_cluster(fatmp, <span class="number">0</span>); <span class="comment">// 读取当前目录的其实蔟号</span></span><br><span class="line">        <span class="comment">// if(strcmp(&quot;AABBCCDD&quot;,currdir.DIR_Name)==0)&#123;//待解决BUG</span></span><br><span class="line">        <span class="comment">//     //判断是根目录</span></span><br><span class="line">        <span class="comment">//     off=16*8;</span></span><br><span class="line">        <span class="comment">// &#125;</span></span><br><span class="line">        <span class="type">int</span> index = ((next - <span class="number">2</span>) * <span class="number">4</span> + <span class="number">64</span>) * <span class="number">512</span> + <span class="number">64</span>;</span><br><span class="line">        <span class="keyword">if</span> (isroot)</span><br><span class="line">            index = <span class="number">16512</span>;</span><br><span class="line">        <span class="keyword">for</span> (<span class="type">int</span> i = index;; i += <span class="keyword">sizeof</span> ftmp)</span><br><span class="line">        &#123;</span><br><span class="line">            disk_read(&amp;ftmp, i, <span class="keyword">sizeof</span> ftmp);</span><br><span class="line">            <span class="keyword">if</span> (ftmp.DIR_Name[<span class="number">0</span>] == (<span class="type">char</span>)<span class="number">0xe5</span>||ftmp.DIR_Name[<span class="number">0</span>] ==<span class="number">0x2e</span>||ftmp.DIR_Name[<span class="number">0</span>] == (<span class="type">char</span>)<span class="number">0xff</span>)</span><br><span class="line">                <span class="keyword">continue</span>;</span><br><span class="line">            <span class="keyword">if</span> (ftmp.DIR_Name[<span class="number">0</span>] == <span class="number">0</span>)</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            <span class="type">char</span> tmp[<span class="number">32</span>];</span><br><span class="line">            <span class="keyword">for</span> (<span class="type">int</span> j = <span class="number">0</span>; j &lt; <span class="number">8</span> &amp;&amp; (ftmp.DIR_Name[j] !=<span class="number">0</span>&amp;&amp;ftmp.DIR_Name[j] !=<span class="string">&#x27; &#x27;</span>); j++)</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="keyword">if</span> (dir_name[<span class="number">0</span>] != <span class="string">&#x27;-&#x27;</span>)</span><br><span class="line">                    <span class="built_in">printf</span>(<span class="string">&quot;%c&quot;</span>, ftmp.DIR_Name[j]);</span><br><span class="line">                <span class="comment">// if (ftmp.DIR_Ext[0] == 0x20)</span></span><br><span class="line">                <span class="comment">// &#123;</span></span><br><span class="line">                <span class="comment">// 是目录,而不是文件夹</span></span><br><span class="line">                tmp[j] = ftmp.DIR_Name[j];</span><br><span class="line">                <span class="keyword">if</span> ((j == <span class="number">7</span> || ftmp.DIR_Name[j + <span class="number">1</span>] == <span class="number">0</span>||ftmp.DIR_Name[j + <span class="number">1</span>] == <span class="string">&#x27; &#x27;</span>))</span><br><span class="line">                    tmp[j + <span class="number">1</span>] = <span class="string">&#x27;\0&#x27;</span>;</span><br><span class="line">                <span class="keyword">if</span> (ftmp.DIR_Ext[<span class="number">0</span>] != <span class="number">0x20</span> &amp;&amp; !(j == <span class="number">7</span> || ftmp.DIR_Name[j + <span class="number">1</span>] == <span class="number">0</span>||ftmp.DIR_Name[j + <span class="number">1</span>] == <span class="string">&#x27; &#x27;</span>))</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="comment">// 说明是文件，</span></span><br><span class="line">                    <span class="type">int</span> k = <span class="number">0</span>;</span><br><span class="line">                    <span class="keyword">for</span> (k = <span class="number">0</span>; k &lt; <span class="number">3</span> &amp;&amp; (ftmp.DIR_Ext[k] != <span class="number">0</span>&amp;&amp;ftmp.DIR_Ext[k] != <span class="string">&#x27; &#x27;</span>); k++)</span><br><span class="line">                    &#123;</span><br><span class="line">                        tmp[j + <span class="number">1</span> + k] = ftmp.DIR_Ext[k];</span><br><span class="line">                    &#125;;</span><br><span class="line">                    tmp[j + <span class="number">1</span> + k] = <span class="string">&#x27;\0&#x27;</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="comment">// &#125;</span></span><br><span class="line">            &#125;;</span><br><span class="line">            <span class="keyword">if</span> (ftmp.DIR_Ext[<span class="number">0</span>] == <span class="number">0x20</span>)</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="built_in">strcpy</span>(res[cnt++], tmp);</span><br><span class="line">            &#125;;</span><br><span class="line"></span><br><span class="line">            <span class="keyword">if</span> ((ftmp.DIR_Ext[<span class="number">0</span>] != <span class="number">0x20</span>&amp;&amp;ftmp.DIR_Ext[<span class="number">0</span>] != <span class="number">0</span>) &amp;&amp; dir_name[<span class="number">0</span>] != <span class="string">&#x27;-&#x27;</span>)</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="built_in">printf</span>(<span class="string">&quot;.&quot;</span>);</span><br><span class="line">                <span class="keyword">for</span> (<span class="type">int</span> j = <span class="number">0</span>; j &lt; <span class="number">3</span>; j++)</span><br><span class="line">                    <span class="keyword">if</span> (dir_name[<span class="number">0</span>] != <span class="string">&#x27;-&#x27;</span>)</span><br><span class="line">                        <span class="built_in">printf</span>(<span class="string">&quot;%c&quot;</span>, ftmp.DIR_Ext[j]);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="built_in">printf</span>(<span class="string">&quot; &quot;</span>);</span><br><span class="line">        &#125;;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;\n&quot;</span>);</span><br><span class="line">    &#125;;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 特殊用处返回当下目录集</span></span><br><span class="line">    <span class="keyword">return</span> res;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h2 id="2-3-测试"><a href="#2-3-测试" class="headerlink" title="2.3 测试"></a>2.3 测试</h2><p><img src="/blog/img/image-20230623225929061.png" alt="image-20230623225929061"></p>
<p><img src="/blog/img/image-20230623230722029.png" alt="image-20230623230722029"></p>
<h1 id="3-功能2-打印fat表"><a href="#3-功能2-打印fat表" class="headerlink" title="3.功能2 (打印fat表)"></a>3.功能2 (打印fat表)</h1><h2 id="3-1实现思路及伪代码"><a href="#3-1实现思路及伪代码" class="headerlink" title="3.1实现思路及伪代码"></a>3.1实现思路及伪代码</h2><p>实现思路：</p>
<p>访问fat表，我们首先要知道fat表在哪个扇区，由于保留扇区占8个扇区（包括引导扇区），所以我们很容易知道，fat表从第九个开始，即8号扇区（0开始计数），又因为fat12文件系统的fat表数据采用小段存储并且每个fat表项占12比特而不是计算机的最小操作单元一字节，所以我们需要额外添加功能函数实现转换和读取。</p>
<p>伪代码：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span>(<span class="type">int</span> i=fat表起始处；i&lt;fat表结尾处；i+=每两个fat表项大小)&#123;</span><br><span class="line">    读取i偏移的两个fat表项，</span><br><span class="line">    调用函数进行转换这个蔟，</span><br><span class="line">    打印到终端</span><br><span class="line">&#125;；</span><br></pre></td></tr></table></figure>

<h2 id="3-2完整的源代码"><a href="#3-2完整的源代码" class="headerlink" title="3.2完整的源代码"></a>3.2完整的源代码</h2><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="comment">//打印文件分配表</span></span><br><span class="line"><span class="type">void</span> <span class="title function_">print_fat</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">int</span> index=<span class="number">4096</span>;</span><br><span class="line">    <span class="keyword">for</span>(<span class="type">int</span> i=index;i&lt;<span class="number">10240</span>;i+=(<span class="keyword">sizeof</span> fatmp))&#123;</span><br><span class="line">    disk_read(&amp;fatmp,i,<span class="keyword">sizeof</span> fatmp);</span><br><span class="line">    <span class="type">int</span> left=read_cluster(fatmp,<span class="number">0</span>);</span><br><span class="line">    <span class="type">int</span> right=read_cluster(fatmp,<span class="number">1</span>);</span><br><span class="line">    <span class="keyword">if</span>(left!=<span class="number">0</span>)</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;index=%d 左边蔟%d \n&quot;</span>,(i<span class="number">-4096</span>)/<span class="number">3</span>*<span class="number">2</span>,left);</span><br><span class="line">    <span class="keyword">if</span>(right!=<span class="number">0</span>)</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;index=%d 右边蔟%d \n&quot;</span>,(i<span class="number">-4096</span>)/<span class="number">3</span>*<span class="number">2</span>+<span class="number">1</span>,right);</span><br><span class="line">&#125;</span><br><span class="line">&#125;;</span><br><span class="line"><span class="type">int</span> <span class="title function_">read_cluster</span><span class="params">(<span class="keyword">struct</span> fat f,<span class="type">int</span> flag)</span>&#123;</span><br><span class="line">    <span class="type">int</span> ans=<span class="number">0</span>;</span><br><span class="line">    <span class="keyword">if</span>(flag==<span class="number">0</span>)&#123;<span class="comment">//读取左边的蔟</span></span><br><span class="line">        f.f[<span class="number">1</span>]&lt;&lt;=<span class="number">4</span>;</span><br><span class="line">        ans=f.f[<span class="number">1</span>];</span><br><span class="line">        ans&lt;&lt;=<span class="number">4</span>;</span><br><span class="line">        ans+=f.f[<span class="number">0</span>];</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">else</span> &#123;<span class="comment">//读取右边的蔟</span></span><br><span class="line">        ans=f.f[<span class="number">2</span>];</span><br><span class="line">        ans&lt;&lt;=<span class="number">4</span>;</span><br><span class="line">        f.f[<span class="number">1</span>]&gt;&gt;=<span class="number">4</span>;</span><br><span class="line">        ans+=f.f[<span class="number">1</span>];</span><br><span class="line">    &#125;;</span><br><span class="line">    <span class="keyword">return</span> ans;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="3-3测试"><a href="#3-3测试" class="headerlink" title="3.3测试"></a>3.3测试</h2><p>winhex上查看u盘的扇区信息，图中从4096开始的就是fat表：</p>
<p><img src="/blog/img/image-20230623222255133.png" alt="image-20230623222255133"></p>
<p>我们在实现的fat12文件系统上输入fat命令即可打印fat表，并且是经过转换的的十进制：</p>
<p><img src="/blog/img/image-20230623222559771.png" alt="image-20230623222559771"></p>
<h1 id="4-功能3（打印文件分配表）"><a href="#4-功能3（打印文件分配表）" class="headerlink" title="4. 功能3（打印文件分配表）"></a>4. 功能3（打印文件分配表）</h1><h2 id="4-1实现思路及伪代码"><a href="#4-1实现思路及伪代码" class="headerlink" title="4.1实现思路及伪代码"></a>4.1实现思路及伪代码</h2><p>思路：</p>
<p>经过计算我们很容易得知根目录的起始扇区，然后我们就可以打印根目录的文件分配表，每32个字节的读取（文件分配表的大小），</p>
<p>然后输出子目录和文件的文件名包括拓展名，起始蔟号，大小等等。</p>
<p>伪代码：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span>(<span class="type">int</span> i=根目录起始处；i&lt;根目录结束处；i+=<span class="keyword">sizeof</span> FCB)&#123;</span><br><span class="line">    <span class="keyword">if</span>(该文件分配表的开始字节不为未分配结束符)</span><br><span class="line">        print(文件分配表的名字，文件分配表的拓展名等等)；</span><br><span class="line">    <span class="keyword">if</span>（该文件分配表的开始字节为结束标识符）<span class="keyword">break</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="4-2完整的源代码"><a href="#4-2完整的源代码" class="headerlink" title="4.2完整的源代码"></a>4.2完整的源代码</h2><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="comment">//打印FCB</span></span><br><span class="line"><span class="type">void</span> <span class="title function_">print_fcb</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="type">int</span> index=<span class="number">16384</span>;</span><br><span class="line">    <span class="keyword">for</span>(<span class="type">int</span> i=index;i&lt;<span class="number">23552</span>;i+=(<span class="keyword">sizeof</span> fcb))&#123;<span class="comment">//扫描224个子目录</span></span><br><span class="line">    disk_read(&amp;ftmp,i,<span class="keyword">sizeof</span> ftmp);</span><br><span class="line">    <span class="keyword">if</span>(ftmp.DIR_Name[<span class="number">0</span>]==<span class="number">0</span>)<span class="keyword">break</span>;</span><br><span class="line">    <span class="keyword">if</span>(ftmp.DIR_Name[<span class="number">0</span>]!=(<span class="type">char</span>)<span class="number">0xe5</span>)&#123;</span><br><span class="line">        <span class="keyword">if</span>(ftmp.DIR_Name[<span class="number">0</span>]==<span class="string">&#x27;A&#x27;</span>||ftmp.DIR_Name[<span class="number">0</span>]==<span class="number">0x01</span>)&#123;</span><br><span class="line">            <span class="comment">//说明是长文件名或这带空格</span></span><br><span class="line">            <span class="type">char</span> name[<span class="number">32</span>];</span><br><span class="line">            disk_read(&amp;name,i,<span class="keyword">sizeof</span> ftmp);</span><br><span class="line">            <span class="built_in">printf</span>(<span class="string">&quot;大概文件名：&quot;</span>);</span><br><span class="line">            <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">1</span>;i&lt;<span class="number">32</span>;i++)&#123;</span><br><span class="line">                <span class="built_in">printf</span>(<span class="string">&quot;%c&quot;</span>,name[i]);</span><br><span class="line">            &#125;;</span><br><span class="line">            <span class="built_in">printf</span>(<span class="string">&quot;\n&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span>(ftmp.DIR_Name[<span class="number">0</span>]!=(<span class="type">char</span>)<span class="number">0xFF</span>)&#123;</span><br><span class="line">            <span class="comment">//说明是上次的长文件名</span></span><br><span class="line">            <span class="built_in">printf</span>(<span class="string">&quot;文件名: &quot;</span>);</span><br><span class="line">            <span class="keyword">for</span>(<span class="type">int</span> j=<span class="number">0</span>;j&lt;<span class="number">8</span>&amp;&amp;ftmp.DIR_Name[j]!=<span class="string">&#x27; &#x27;</span>;j++)&#123;</span><br><span class="line">                <span class="built_in">printf</span>(<span class="string">&quot;%c&quot;</span>,ftmp.DIR_Name[j]);</span><br><span class="line">            &#125;;</span><br><span class="line">            <span class="keyword">if</span>(ftmp.DIR_Ext[<span class="number">0</span>]!=<span class="string">&#x27; &#x27;</span>)&#123;</span><br><span class="line">                <span class="built_in">printf</span>(<span class="string">&quot;.&quot;</span>);</span><br><span class="line">              <span class="keyword">for</span>(<span class="type">int</span> j=<span class="number">0</span>;j&lt;<span class="number">3</span>&amp;&amp;ftmp.DIR_Name[j]!=<span class="string">&#x27; &#x27;</span>;j++)&#123;</span><br><span class="line">                <span class="built_in">printf</span>(<span class="string">&quot;%c&quot;</span>,ftmp.DIR_Ext[j]);</span><br><span class="line">            &#125;;  </span><br><span class="line">            &#125;;</span><br><span class="line">            <span class="built_in">printf</span>(<span class="string">&quot;\n&quot;</span>);</span><br><span class="line">            <span class="built_in">printf</span>(<span class="string">&quot;数据起始蔟号: %u\n&quot;</span>,ftmp.DIR_FstClus);</span><br><span class="line">            <span class="built_in">printf</span>(<span class="string">&quot;文件大小: %u\n&quot;</span>,ftmp.DIR_FileSize);</span><br><span class="line">            <span class="built_in">printf</span>(<span class="string">&quot;\n&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="4-3测试"><a href="#4-3测试" class="headerlink" title="4.3测试"></a>4.3测试</h2><p>根目录文件夹和文件：</p>
<p><img src="/blog/img/image-20230623223601753.png" alt="image-20230623223601753"></p>
<p>打印根目录fcb表；</p>
<p><img src="/blog/img/image-20230623223639776.png" alt="image-20230623223639776"></p>
<h1 id="5-功能5（cd）"><a href="#5-功能5（cd）" class="headerlink" title="5.功能5（cd）"></a>5.功能5（cd）</h1><h2 id="5-1实现思路及伪代码"><a href="#5-1实现思路及伪代码" class="headerlink" title="5.1实现思路及伪代码"></a>5.1实现思路及伪代码</h2><p>思路：</p>
<p>我们用一个fcb结构体记录当前目录，当进入子目录时，访问当前目录的fcb表的蔟号，到数据去查找并访问子目录即可</p>
<p>伪代码：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">访问当前目录的fcb，</span><br><span class="line">    访问fat表，</span><br><span class="line">    访问子目录的数据区，</span><br><span class="line">    <span class="keyword">if</span>（存在子目录）进入子目录</span><br><span class="line">    <span class="keyword">else</span> 报错</span><br></pre></td></tr></table></figure>

<h2 id="5-2完整源码"><a href="#5-2完整源码" class="headerlink" title="5.2完整源码"></a>5.2完整源码</h2><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">cd</span><span class="params">(<span class="type">const</span> <span class="type">char</span> *dir)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="type">char</span> dir_name[<span class="number">32</span>];</span><br><span class="line">    <span class="built_in">strcpy</span>(dir_name, dir);</span><br><span class="line">    <span class="keyword">if</span> (dir_name[<span class="number">0</span>] != <span class="string">&#x27;.&#x27;</span> || dir_name[<span class="number">1</span>] != <span class="string">&#x27;.&#x27;</span>)</span><br><span class="line">    &#123;</span><br><span class="line">            <span class="type">int</span> clus;</span><br><span class="line">                <span class="keyword">if</span> (isroot)</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="comment">// 根目录特殊处理</span></span><br><span class="line">                    <span class="keyword">for</span> (<span class="type">int</span> j = <span class="number">16384</span>;; j += <span class="keyword">sizeof</span> fcb)</span><br><span class="line">                    &#123;</span><br><span class="line">                        disk_read(&amp;ftmp, j, <span class="keyword">sizeof</span> ftmp);</span><br><span class="line">                        <span class="type">int</span> j = <span class="number">0</span>;</span><br><span class="line">                        <span class="keyword">for</span> (j = <span class="number">0</span>; ftmp.DIR_Name[j] != <span class="string">&#x27; &#x27;</span> &amp;&amp; j &lt; <span class="number">8</span>; j++)</span><br><span class="line">                        &#123;</span><br><span class="line">                        &#125;;</span><br><span class="line">                        ftmp.DIR_Name[j] = <span class="string">&#x27;\0&#x27;</span>;</span><br><span class="line">                        <span class="keyword">if</span> (<span class="built_in">strcmp</span>(ftmp.DIR_Name, dir_name) == <span class="number">0</span>)</span><br><span class="line">                        &#123;</span><br><span class="line">                            <span class="comment">// 找到</span></span><br><span class="line">                            fatmp.f[<span class="number">0</span>] = currdir.DIR_FstClus[<span class="number">0</span>];</span><br><span class="line">                            fatmp.f[<span class="number">1</span>] = currdir.DIR_FstClus[<span class="number">1</span>];</span><br><span class="line">                            <span class="type">int</span> clus = read_cluster(fatmp, <span class="number">0</span>);</span><br><span class="line">                            <span class="type">int</span> index = ((clus - <span class="number">2</span>) * <span class="number">4</span> + <span class="number">64</span>) * <span class="number">512</span>;</span><br><span class="line">                            <span class="keyword">for</span> (<span class="type">int</span> k = <span class="number">0</span>;; k++)</span><br><span class="line">                            &#123;</span><br><span class="line">                                <span class="keyword">if</span> (lastdir[k] == <span class="number">-1</span>)</span><br><span class="line">                                &#123;</span><br><span class="line">                                    <span class="keyword">if</span> (!isroot)</span><br><span class="line">                                        lastdir[k] = index;</span><br><span class="line">                                    <span class="keyword">else</span></span><br><span class="line">                                    &#123;</span><br><span class="line">                                        lastdir[k] = <span class="number">16384</span>;</span><br><span class="line">                                    &#125;</span><br><span class="line">                                    <span class="keyword">break</span>;</span><br><span class="line">                                &#125;</span><br><span class="line">                            &#125;</span><br><span class="line">                            currdir = ftmp;</span><br><span class="line">                            <span class="built_in">strcat</span>(currdir_str, <span class="string">&quot;/&quot;</span>);</span><br><span class="line">                            <span class="built_in">strcat</span>(currdir_str, dir_name);</span><br><span class="line">                            isroot = <span class="number">0</span>;</span><br><span class="line">                            <span class="keyword">return</span>;</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;;</span><br><span class="line">                    <span class="built_in">printf</span>(<span class="string">&quot;当前根目录没有此目录\n&quot;</span>);</span><br><span class="line">                    <span class="keyword">return</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">else</span></span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="comment">// 不是根目录，去数据去寻找</span></span><br><span class="line">                    fatmp.f[<span class="number">0</span>] = currdir.DIR_FstClus[<span class="number">0</span>];</span><br><span class="line">                    fatmp.f[<span class="number">1</span>] = currdir.DIR_FstClus[<span class="number">1</span>];</span><br><span class="line">                    clus = read_cluster(fatmp, <span class="number">0</span>);</span><br><span class="line">                    <span class="type">int</span> index = ((clus - <span class="number">2</span>) * <span class="number">4</span> + <span class="number">64</span>) * <span class="number">512</span>;</span><br><span class="line">                    <span class="keyword">for</span> (<span class="type">int</span> j = index;; j += <span class="keyword">sizeof</span> ftmp)</span><br><span class="line">                    &#123;</span><br><span class="line">                        disk_read(&amp;ftmp, j, <span class="keyword">sizeof</span> ftmp);</span><br><span class="line">                        <span class="type">int</span> j = <span class="number">0</span>;</span><br><span class="line">                        <span class="keyword">for</span> (j = <span class="number">0</span>; j &lt; <span class="number">8</span> &amp;&amp; (ftmp.DIR_Name[j] != <span class="string">&#x27; &#x27;</span>&amp;&amp;ftmp.DIR_Name[j] != <span class="number">0</span>); j++)</span><br><span class="line">                            ;</span><br><span class="line">                        ftmp.DIR_Name[j] = <span class="string">&#x27;\0&#x27;</span>;</span><br><span class="line">                        <span class="keyword">if</span> (<span class="built_in">strcmp</span>(ftmp.DIR_Name, dir_name) == <span class="number">0</span>)</span><br><span class="line">                        &#123;</span><br><span class="line">                            <span class="comment">// 找到目标文件夹FCB;</span></span><br><span class="line">                            currdir = ftmp;</span><br><span class="line">                            <span class="keyword">for</span> (<span class="type">int</span> k = <span class="number">0</span>;; k++)</span><br><span class="line">                            &#123;</span><br><span class="line">                                <span class="keyword">if</span> (lastdir[k] == <span class="number">-1</span>)</span><br><span class="line">                                &#123;</span><br><span class="line">                                    <span class="keyword">if</span> (!isroot)</span><br><span class="line">                                        lastdir[k] = index;</span><br><span class="line">                                    <span class="keyword">else</span></span><br><span class="line">                                    &#123;</span><br><span class="line">                                        lastdir[k] = <span class="number">16384</span>;</span><br><span class="line">                                    &#125;</span><br><span class="line">                                    <span class="keyword">break</span>;</span><br><span class="line">                                &#125;</span><br><span class="line">                            &#125;</span><br><span class="line">                            isroot = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">                            <span class="comment">/*</span></span><br><span class="line"><span class="comment">                            在当前目录新加</span></span><br><span class="line"><span class="comment">                            */</span></span><br><span class="line">                            <span class="built_in">strcat</span>(currdir_str, <span class="string">&quot;/&quot;</span>);</span><br><span class="line">                            <span class="built_in">strcat</span>(currdir_str, dir_name);</span><br><span class="line">                            <span class="keyword">return</span>;</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;当前目录下没有此目录\n&quot;</span>);</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">else</span> <span class="keyword">if</span> (dir_name[<span class="number">0</span>] != <span class="string">&#x27;/&#x27;</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">// 退回上级目录</span></span><br><span class="line">        <span class="type">int</span> cnt = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">0</span>; dir_name[i] != <span class="string">&#x27;\0&#x27;</span> &amp;&amp; i &lt; <span class="number">8</span>; i++)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">if</span> (dir_name[i] == <span class="string">&#x27;.&#x27;</span>)</span><br><span class="line">                cnt++;</span><br><span class="line">            ;</span><br><span class="line">        &#125;;</span><br><span class="line">        cnt = <span class="number">-1</span>;</span><br><span class="line">        <span class="keyword">if</span> (cnt == <span class="number">0</span>)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="built_in">printf</span>(<span class="string">&quot;输入参数有误\n&quot;</span>);</span><br><span class="line">            <span class="keyword">return</span>;</span><br><span class="line">        &#125;;</span><br><span class="line">        <span class="comment">/*</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">0</span>;; i++)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">if</span> (lastdir[i] == <span class="number">-1</span>)</span><br><span class="line">            &#123;</span><br><span class="line">                disk_read(&amp;ftmp, lastdir[i - <span class="number">1</span>], <span class="keyword">sizeof</span> ftmp);</span><br><span class="line">                currdir = ftmp;</span><br><span class="line">                lastdir[i - <span class="number">1</span>] = <span class="number">-1</span>;</span><br><span class="line">                <span class="type">int</span> len = <span class="built_in">strlen</span>(currdir_str);</span><br><span class="line">                <span class="keyword">while</span> (len--)</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="keyword">if</span> (currdir_str[len] == <span class="string">&#x27;/&#x27;</span>)</span><br><span class="line">                    &#123;</span><br><span class="line">                        currdir_str[len] = <span class="string">&#x27;\0&#x27;</span>;</span><br><span class="line">                        <span class="keyword">break</span>;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">return</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        cd(currdir_str);</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="5-3测试"><a href="#5-3测试" class="headerlink" title="5.3测试"></a>5.3测试</h2><p>一个子目录：</p>
<p><img src="/blog/img/image-20230623214228340.png" alt="image-20230623214228340"></p>
<p>使用cd进入：</p>
<p><img src="/blog/img/image-20230623214429206.png" alt="image-20230623214429206"></p>
<h1 id="5-功能4（删除和创建文件）"><a href="#5-功能4（删除和创建文件）" class="headerlink" title="5.功能4（删除和创建文件）"></a>5.功能4（删除和创建文件）</h1><h2 id="5-1思路及伪代码"><a href="#5-1思路及伪代码" class="headerlink" title="5.1思路及伪代码"></a>5.1思路及伪代码</h2><p>思路：创建时先访问当前目录的fcb表，找到数据区，查看数据区是否还有空闲剩余空间，有则将要创建的文件写入，并在fat表查找未使用蔟，然后分配蔟号，同理删除时最后只是将文件按控制块和对应的蔟标记为未使用，</p>
<p>伪代码：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">创建：</span><br><span class="line">    访问当前目录的数据区，</span><br><span class="line">    <span class="keyword">if</span>（数据区还有剩余空间）&#123;</span><br><span class="line">    访问fat表；</span><br><span class="line">        <span class="keyword">if</span>（fat表还有未分配蔟）</span><br><span class="line">        分配蔟分配空间记录在数据区中</span><br><span class="line">&#125;</span><br><span class="line">删除：</span><br><span class="line">     访问当前目录的数据区，</span><br><span class="line">    <span class="keyword">if</span>（找到文件）&#123;</span><br><span class="line">    访问fat表；</span><br><span class="line">        将fat表和FCB标记为未使用；</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="5-2完整源代码"><a href="#5-2完整源代码" class="headerlink" title="5.2完整源代码"></a>5.2完整源代码</h2><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">touch</span><span class="params">(<span class="type">const</span> <span class="type">char</span> *dir)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="type">char</span> *st;</span><br><span class="line">    st=<span class="built_in">strstr</span>(dir,<span class="string">&quot;.&quot;</span>);</span><br><span class="line">    <span class="keyword">if</span>(st==<span class="literal">NULL</span>)&#123;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;没有文件后缀\n&quot;</span>);</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;;</span><br><span class="line">    <span class="type">int</span> len=<span class="built_in">strlen</span>(st+<span class="number">1</span>);</span><br><span class="line">    <span class="keyword">if</span>(len&gt;<span class="number">3</span>)&#123;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;后缀过长,请重新输入\n&quot;</span>);</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;;</span><br><span class="line">    </span><br><span class="line">    <span class="class"><span class="keyword">struct</span> <span class="title">FCB</span> <span class="title">new_dir</span>;</span></span><br><span class="line">    <span class="built_in">strcpy</span>(new_dir.DIR_Ext,st+<span class="number">1</span>);</span><br><span class="line">    (*st)=<span class="string">&#x27;\0&#x27;</span>;</span><br><span class="line">    len=<span class="built_in">strlen</span>(dir);</span><br><span class="line">    <span class="keyword">if</span>(len&gt;<span class="number">8</span>)&#123;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;文件名过长,请重新输入&quot;</span>);</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;;</span><br><span class="line">    <span class="type">int</span> pt=<span class="number">0</span>;</span><br><span class="line">    <span class="keyword">for</span>(pt=<span class="number">0</span>;new_dir.DIR_Ext[pt]!=<span class="string">&#x27;\0&#x27;</span>&amp;&amp;pt&lt;<span class="number">3</span>;pt++);</span><br><span class="line">    <span class="keyword">if</span>(pt&lt;<span class="number">3</span>)&#123;</span><br><span class="line">        <span class="keyword">for</span>(<span class="type">int</span> i=pt;i&lt;<span class="number">3</span>;i++)</span><br><span class="line">    new_dir.DIR_Ext[i]=<span class="string">&#x27; &#x27;</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">strcpy</span>(new_dir.DIR_Name, dir); <span class="comment">// 我是傻逼，当然要用strcmp函数复制</span></span><br><span class="line">    <span class="keyword">for</span>(pt=<span class="number">0</span>;new_dir.DIR_Name[pt]!=<span class="string">&#x27;\0&#x27;</span>&amp;&amp;pt&lt;<span class="number">8</span>;pt++);</span><br><span class="line">    <span class="keyword">if</span>(pt&lt;<span class="number">8</span>)&#123;</span><br><span class="line">    <span class="keyword">for</span>(<span class="type">int</span> i=pt;i&lt;<span class="number">8</span>;i++)</span><br><span class="line">    new_dir.DIR_Name[i]=<span class="number">0</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    new_dir.DIR_Attr = <span class="number">0x20</span>;</span><br><span class="line">    <span class="type">time_t</span> t;     <span class="comment">// 将t声明为时间变量</span></span><br><span class="line">    <span class="class"><span class="keyword">struct</span> <span class="title">tm</span> *<span class="title">p</span>;</span> <span class="comment">// struct tm是一个结构体，声明一个结构体指针</span></span><br><span class="line">    time(&amp;t);</span><br><span class="line">    p = localtime(&amp;t); <span class="comment">// 获得当地的时间</span></span><br><span class="line">    <span class="comment">// printf(&quot;%d-%d-%d %d:%d:%d&quot;,1900+p-&gt;tm_year,1+p-&gt;tm_mon,p-&gt;tm_mday,p-&gt;tm_hour,p-&gt;tm_min,p-&gt;tm_sec);</span></span><br><span class="line">    new_dir.DIR_CreateDate = <span class="number">1900</span> + p-&gt;tm_year;</span><br><span class="line">    new_dir.DIR_LastDate = <span class="number">1900</span> + p-&gt;tm_year;</span><br><span class="line">    fatmp.f[<span class="number">0</span>] = currdir.DIR_FstClus[<span class="number">0</span>];</span><br><span class="line">    fatmp.f[<span class="number">1</span>] = currdir.DIR_FstClus[<span class="number">1</span>];</span><br><span class="line">    <span class="type">int</span> clus = read_cluster(fatmp, <span class="number">0</span>);</span><br><span class="line">    <span class="type">int</span> index = ((clus - <span class="number">2</span>) * <span class="number">4</span> + <span class="number">64</span>) * <span class="number">512</span>;</span><br><span class="line">    <span class="keyword">if</span> (isroot)</span><br><span class="line">        index = <span class="number">16384</span>;</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">int</span> i = index; i &lt; index + <span class="number">4</span> * <span class="number">512</span>; i += <span class="keyword">sizeof</span> ftmp)</span><br><span class="line">    &#123;</span><br><span class="line">        disk_read(&amp;ftmp, i, <span class="keyword">sizeof</span> ftmp);</span><br><span class="line">        <span class="keyword">if</span> (ftmp.DIR_Name[<span class="number">0</span>] == (<span class="type">char</span>)<span class="number">0xe5</span> || ftmp.DIR_Name[<span class="number">0</span>] == (<span class="type">char</span>)<span class="number">0xff</span> || ftmp.DIR_Name[<span class="number">0</span>] == <span class="number">0</span>)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">4096</span> + <span class="number">3</span>; i &lt; <span class="number">4096</span> + <span class="number">12</span> * <span class="number">512</span>; i += (<span class="keyword">sizeof</span> fatmp))</span><br><span class="line">            &#123;</span><br><span class="line">                disk_read(&amp;fatmp, i, <span class="keyword">sizeof</span> fatmp);</span><br><span class="line">                <span class="type">int</span> next_clus = read_cluster(fatmp, <span class="number">0</span>);</span><br><span class="line">                <span class="keyword">if</span> (next_clus != <span class="number">0</span>)</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="comment">// 左边使用蔟</span></span><br><span class="line">                    next_clus = read_cluster(fatmp, <span class="number">1</span>);</span><br><span class="line">                    <span class="keyword">if</span> (next_clus != <span class="number">0</span>)</span><br><span class="line">                    &#123;</span><br><span class="line">                        <span class="comment">// 右边已使用蔟</span></span><br><span class="line">                        <span class="keyword">continue</span>;</span><br><span class="line">                    &#125;</span><br><span class="line">                    <span class="keyword">else</span> <span class="keyword">if</span> (next_clus == <span class="number">0</span>)</span><br><span class="line">                    &#123;</span><br><span class="line">                        <span class="comment">// 右边未使用蔟</span></span><br><span class="line">                        write_cluster(&amp;fatmp, <span class="number">1</span>, <span class="number">0xfff</span>);</span><br><span class="line">                        next_clus = (i - <span class="number">4096</span>) / <span class="number">3</span> * <span class="number">2</span> + <span class="number">1</span>;</span><br><span class="line">                    &#125;;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">else</span> <span class="keyword">if</span> (next_clus == <span class="number">0</span>)</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="comment">// 左边未使用</span></span><br><span class="line">                    write_cluster(&amp;fatmp, <span class="number">0</span>, <span class="number">0xfff</span>);</span><br><span class="line">                    next_clus = (i - <span class="number">4096</span>) / <span class="number">3</span> * <span class="number">2</span>;</span><br><span class="line">                &#125;;</span><br><span class="line">                <span class="class"><span class="keyword">struct</span> <span class="title">fat_one</span> <span class="title">fot</span>;</span></span><br><span class="line">                write_cluster_end(&amp;fot, next_clus);</span><br><span class="line">                new_dir.DIR_FstClus[<span class="number">0</span>] = fot.f[<span class="number">0</span>];</span><br><span class="line">                new_dir.DIR_FstClus[<span class="number">1</span>] = fot.f[<span class="number">1</span>];</span><br><span class="line">                disk_write(&amp;fatmp, i, <span class="keyword">sizeof</span> fatmp);</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            &#125;;</span><br><span class="line">            disk_write(&amp;new_dir, i, <span class="keyword">sizeof</span> ftmp);</span><br><span class="line">            <span class="built_in">printf</span>(<span class="string">&quot;创建成功\n&quot;</span>);</span><br><span class="line">            <span class="keyword">return</span>;</span><br><span class="line">        &#125;;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;当前目录下没有足够空间分配\n&quot;</span>);</span><br><span class="line">    <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="type">void</span> <span class="title function_">rm</span><span class="params">(<span class="type">const</span> <span class="type">char</span> *dir)</span></span><br><span class="line">&#123;</span><br><span class="line"></span><br><span class="line">    <span class="type">char</span> dir_name[<span class="number">32</span>];</span><br><span class="line">    <span class="type">char</span> dir_ext[<span class="number">32</span>];</span><br><span class="line">    <span class="built_in">strcpy</span>(dir_name, dir);</span><br><span class="line">    <span class="type">int</span> isfile=<span class="number">0</span>;</span><br><span class="line">    <span class="type">char</span> *st=<span class="literal">NULL</span>;</span><br><span class="line">    st=<span class="built_in">strstr</span>(dir,<span class="string">&quot;.&quot;</span>);</span><br><span class="line">    <span class="keyword">if</span>(st!=<span class="literal">NULL</span>)&#123;</span><br><span class="line">        <span class="comment">//确认是文件</span></span><br><span class="line">        isfile=<span class="number">1</span>;</span><br><span class="line">        <span class="built_in">strcpy</span>(dir_ext,st+<span class="number">1</span>);</span><br><span class="line">        st=<span class="built_in">strstr</span>(dir_name,<span class="string">&quot;.&quot;</span>);</span><br><span class="line">        (*st)=<span class="string">&#x27;\0&#x27;</span>;</span><br><span class="line">    &#125;;</span><br><span class="line">    <span class="keyword">if</span> (<span class="built_in">strcmp</span>(dir_name, <span class="string">&quot;&quot;</span>) != <span class="number">0</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="type">int</span> clus;</span><br><span class="line">        <span class="comment">// 不是根目录，去数据去寻找</span></span><br><span class="line">        fatmp.f[<span class="number">0</span>] = currdir.DIR_FstClus[<span class="number">0</span>];</span><br><span class="line">        fatmp.f[<span class="number">1</span>] = currdir.DIR_FstClus[<span class="number">1</span>];</span><br><span class="line">        clus = read_cluster(fatmp, <span class="number">0</span>);</span><br><span class="line">        <span class="type">int</span> index = ((clus - <span class="number">2</span>) * <span class="number">4</span> + <span class="number">64</span>) * <span class="number">512</span>;</span><br><span class="line">        <span class="keyword">if</span> (isroot)</span><br><span class="line">            index = <span class="number">16384</span>; <span class="comment">// 根目录特殊处理</span></span><br><span class="line">        <span class="keyword">for</span> (<span class="type">int</span> j = index;; j += <span class="keyword">sizeof</span> ftmp)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">if</span>(j==<span class="number">39360</span>)&#123;</span><br><span class="line">                <span class="built_in">printf</span>(<span class="string">&quot;&quot;</span>);</span><br><span class="line">            &#125;</span><br><span class="line">            disk_read(&amp;ftmp, j, <span class="keyword">sizeof</span> ftmp);</span><br><span class="line">            <span class="type">int</span> k = <span class="number">0</span>;</span><br><span class="line">            <span class="keyword">if</span> (ftmp.DIR_Name[<span class="number">0</span>] == <span class="number">0</span>)</span><br><span class="line">                <span class="keyword">break</span>; <span class="comment">// 找完了，没找到，</span></span><br><span class="line">            <span class="keyword">for</span> (k = <span class="number">0</span>; k &lt; <span class="number">8</span> &amp;&amp; ftmp.DIR_Name[k] != <span class="number">0</span>; k++)</span><br><span class="line">                ;</span><br><span class="line">            <span class="keyword">if</span>(k&lt;<span class="number">7</span>)ftmp.DIR_Name[k] = <span class="string">&#x27;\0&#x27;</span>;</span><br><span class="line">            <span class="keyword">for</span>(<span class="type">int</span> g=<span class="number">0</span>;g&lt;<span class="number">8</span>;g++)&#123;</span><br><span class="line">                <span class="keyword">if</span>(ftmp.DIR_Name[g]==<span class="string">&#x27; &#x27;</span>)ftmp.DIR_Name[g]=<span class="number">0</span>;</span><br><span class="line">            &#125;;</span><br><span class="line">            <span class="keyword">if</span> (<span class="built_in">strcmp</span>(ftmp.DIR_Name, dir_name) == <span class="number">0</span>)</span><br><span class="line">            &#123;   </span><br><span class="line">                <span class="keyword">if</span>(</span><br><span class="line">                    ((ftmp.DIR_Ext[<span class="number">0</span>]==<span class="number">0</span>||ftmp.DIR_Ext[<span class="number">0</span>]==<span class="string">&#x27; &#x27;</span>)&amp;&amp;isfile==<span class="number">1</span>)||</span><br><span class="line">                (ftmp.DIR_Ext[<span class="number">0</span>]!=<span class="number">0</span>&amp;&amp;isfile==<span class="number">0</span>)</span><br><span class="line">                )</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="comment">//只是文件夹和文件名字重复</span></span><br><span class="line">                    <span class="keyword">continue</span>;</span><br><span class="line">                &#125;;</span><br><span class="line">                <span class="keyword">if</span>(isfile)&#123;</span><br><span class="line">                    <span class="type">char</span> fcb_ext[<span class="number">32</span>];</span><br><span class="line">            <span class="keyword">for</span> (k = <span class="number">0</span>; k &lt; <span class="number">3</span>&amp;&amp; (ftmp.DIR_Ext[k] != <span class="number">0</span>&amp;&amp;ftmp.DIR_Ext[k] != <span class="string">&#x27; &#x27;</span>); k++);</span><br><span class="line">            ftmp.DIR_Ext[k] = <span class="string">&#x27;\0&#x27;</span>;</span><br><span class="line">                    <span class="built_in">strcpy</span>(fcb_ext,ftmp.DIR_Ext);</span><br><span class="line">                    <span class="keyword">if</span>(<span class="built_in">strcmp</span>(fcb_ext,dir_ext)!=<span class="number">0</span>)&#123;</span><br><span class="line">                        <span class="comment">//文件拓展名不匹配</span></span><br><span class="line">                        <span class="keyword">continue</span>;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="comment">// 找到目标文件FCB;</span></span><br><span class="line"></span><br><span class="line">                fatmp.f[<span class="number">0</span>] = ftmp.DIR_FstClus[<span class="number">0</span>];</span><br><span class="line">                fatmp.f[<span class="number">1</span>] = ftmp.DIR_FstClus[<span class="number">1</span>];</span><br><span class="line">                <span class="type">int</span> clus = read_cluster(fatmp, <span class="number">0</span>);</span><br><span class="line">                <span class="type">int</span> index = clus / <span class="number">2</span> * <span class="number">3</span> + <span class="number">4096</span>;</span><br><span class="line">                disk_read(&amp;fatmp, index, <span class="keyword">sizeof</span> fatmp);</span><br><span class="line">                <span class="keyword">if</span> (clus % <span class="number">2</span> == <span class="number">0</span>)</span><br><span class="line">                &#123;</span><br><span class="line">                    write_cluster(&amp;fatmp, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">else</span></span><br><span class="line">                &#123;</span><br><span class="line">                    write_cluster(&amp;fatmp, <span class="number">1</span>, <span class="number">0</span>);</span><br><span class="line">                &#125;;</span><br><span class="line">                disk_write(&amp;fatmp, index, <span class="keyword">sizeof</span> fatmp); <span class="comment">// 更新fat表</span></span><br><span class="line">                <span class="built_in">memset</span>(&amp;ftmp, <span class="number">0XFF</span>, <span class="keyword">sizeof</span> ftmp);</span><br><span class="line">                disk_write(&amp;ftmp, j, <span class="keyword">sizeof</span> ftmp); <span class="comment">// 更新数据区</span></span><br><span class="line">                <span class="keyword">return</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;当前目录下没有此文件或目录\n&quot;</span>);</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;参数有误\n&quot;</span>);</span><br><span class="line">    <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="5-3测试-1"><a href="#5-3测试-1" class="headerlink" title="5.3测试"></a>5.3测试</h2><p>touch:</p>
<p><img src="/blog/img/image-20230623214937354.png" alt="image-20230623214937354"></p>
<p>rm:</p>
<p><img src="/blog/img/image-20230623215111176.png" alt="image-20230623215111176"></p>
<p><img src="/blog/img/image-20230623215053138.png" alt="image-20230623215053138"></p>
<h1 id="6-功能5（创建文件夹和删除）"><a href="#6-功能5（创建文件夹和删除）" class="headerlink" title="6.功能5（创建文件夹和删除）"></a>6.功能5（创建文件夹和删除）</h1><h2 id="6-1思路和伪代码"><a href="#6-1思路和伪代码" class="headerlink" title="6.1思路和伪代码"></a>6.1思路和伪代码</h2><p>思路：</p>
<p>和上一个创建删除文件的思路类似，因为目录也是一种特殊的文件</p>
<p>伪代码：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">创建：</span><br><span class="line">    访问当前目录的数据区，</span><br><span class="line">    <span class="keyword">if</span>（数据区还有剩余空间）&#123;</span><br><span class="line">    访问fat表；</span><br><span class="line">        <span class="keyword">if</span>（fat表还有未分配蔟）</span><br><span class="line">        分配蔟分配空间记录在数据区中</span><br><span class="line">&#125;</span><br><span class="line">删除：</span><br><span class="line">     访问当前目录的数据区，</span><br><span class="line">    <span class="keyword">if</span>（找到文件）&#123;</span><br><span class="line">    访问fat表；</span><br><span class="line">        将fat表和FCB标记为未使用；</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="6-2源代码"><a href="#6-2源代码" class="headerlink" title="6.2源代码"></a>6.2源代码</h2><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">mkdir</span><span class="params">(<span class="type">const</span> <span class="type">char</span> *dir)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="class"><span class="keyword">struct</span> <span class="title">FCB</span> <span class="title">new_dir</span>;</span></span><br><span class="line">    <span class="built_in">strcpy</span>(new_dir.DIR_Name, dir); <span class="comment">// 我是傻逼，当然要用strcmp函数复制</span></span><br><span class="line">    <span class="built_in">strcpy</span>(new_dir.DIR_Ext,<span class="string">&quot;&quot;</span>);</span><br><span class="line">    <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;i&lt;<span class="number">3</span>;i++)new_dir.DIR_Ext[i]=<span class="number">0</span>;</span><br><span class="line">    new_dir.DIR_FileSize = <span class="number">0</span>;</span><br><span class="line">    new_dir.DIR_Attr = <span class="number">0x10</span>;</span><br><span class="line">    fatmp.f[<span class="number">0</span>] = currdir.DIR_FstClus[<span class="number">0</span>];</span><br><span class="line">    fatmp.f[<span class="number">1</span>] = currdir.DIR_FstClus[<span class="number">1</span>];</span><br><span class="line">    <span class="type">int</span> clus = read_cluster(fatmp, <span class="number">0</span>);</span><br><span class="line">    <span class="type">int</span> index = ((clus - <span class="number">2</span>) * <span class="number">4</span> + <span class="number">64</span>) * <span class="number">512</span>;</span><br><span class="line">    <span class="keyword">if</span> (isroot)</span><br><span class="line">        index = <span class="number">16384</span>;</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">int</span> i = index; i &lt; index + <span class="number">4</span> * <span class="number">512</span>; i += <span class="keyword">sizeof</span> ftmp)</span><br><span class="line">    &#123;</span><br><span class="line">        disk_read(&amp;ftmp, i, <span class="keyword">sizeof</span> ftmp);</span><br><span class="line">        <span class="keyword">if</span> (ftmp.DIR_Name[<span class="number">0</span>] == (<span class="type">char</span>)<span class="number">0xe5</span> || ftmp.DIR_Name[<span class="number">0</span>] == (<span class="type">char</span>)<span class="number">0xff</span> || ftmp.DIR_Name[<span class="number">0</span>] == <span class="number">0</span>)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">4096</span> + <span class="number">3</span>; i &lt; <span class="number">4096</span> + <span class="number">12</span> * <span class="number">512</span>; i += (<span class="keyword">sizeof</span> fatmp))</span><br><span class="line">            &#123;</span><br><span class="line">                disk_read(&amp;fatmp, i, <span class="keyword">sizeof</span> fatmp);</span><br><span class="line">                <span class="type">int</span> next_clus = read_cluster(fatmp, <span class="number">0</span>);</span><br><span class="line">                <span class="keyword">if</span> (next_clus != <span class="number">0</span>)</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="comment">// 左边使用蔟</span></span><br><span class="line">                    next_clus = read_cluster(fatmp, <span class="number">1</span>);</span><br><span class="line">                    <span class="keyword">if</span> (next_clus != <span class="number">0</span>)</span><br><span class="line">                    &#123;</span><br><span class="line">                        <span class="comment">// 右边已使用蔟</span></span><br><span class="line">                        <span class="keyword">continue</span>;</span><br><span class="line">                    &#125;</span><br><span class="line">                    <span class="keyword">else</span> <span class="keyword">if</span> (next_clus == <span class="number">0</span>)</span><br><span class="line">                    &#123;</span><br><span class="line">                        <span class="comment">// 右边未使用蔟</span></span><br><span class="line">                        write_cluster(&amp;fatmp, <span class="number">1</span>, <span class="number">0xfff</span>);</span><br><span class="line">                        next_clus = (i - <span class="number">4096</span>) / <span class="number">3</span> * <span class="number">2</span> + <span class="number">1</span>;</span><br><span class="line">                    &#125;;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">else</span> <span class="keyword">if</span> (next_clus == <span class="number">0</span>)</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="comment">// 左边未使用</span></span><br><span class="line">                    write_cluster(&amp;fatmp, <span class="number">0</span>, <span class="number">0xfff</span>);</span><br><span class="line">                    next_clus = (i - <span class="number">4096</span>) / <span class="number">3</span> * <span class="number">2</span>;</span><br><span class="line">                &#125;;</span><br><span class="line">                <span class="class"><span class="keyword">struct</span> <span class="title">fat_one</span> <span class="title">fot</span>;</span></span><br><span class="line">                write_cluster_end(&amp;fot, next_clus);</span><br><span class="line">                new_dir.DIR_FstClus[<span class="number">0</span>] = fot.f[<span class="number">0</span>];</span><br><span class="line">                new_dir.DIR_FstClus[<span class="number">1</span>] = fot.f[<span class="number">1</span>];</span><br><span class="line">                disk_write(&amp;fatmp, i, <span class="keyword">sizeof</span> fatmp);</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            &#125;;</span><br><span class="line">            disk_write(&amp;new_dir, i, <span class="keyword">sizeof</span> ftmp);</span><br><span class="line">            <span class="built_in">printf</span>(<span class="string">&quot;创建成功\n&quot;</span>);</span><br><span class="line">            <span class="keyword">return</span>;</span><br><span class="line">        &#125;;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;当前目录下没有足够空间分配\n&quot;</span>);</span><br><span class="line">    <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="6-3测试"><a href="#6-3测试" class="headerlink" title="6.3测试"></a>6.3测试</h2><p>mkdir功能：</p>
<p><img src="/blog/img/image-20230623214750670.png" alt="image-20230623214750670"></p>
<p><img src="/blog/img/image-20230623214725323.png" alt="image-20230623214725323"></p>
<h1 id="7-功能6（实现cat）"><a href="#7-功能6（实现cat）" class="headerlink" title="7.功能6（实现cat）"></a>7.功能6（实现cat）</h1><h2 id="7-1思路及伪代码"><a href="#7-1思路及伪代码" class="headerlink" title="7.1思路及伪代码"></a>7.1思路及伪代码</h2><p>思路：</p>
<p>和访问文件控制块类似，最后只要再访问FCB的数据区读取数据即可</p>
<h2 id="7-2源代码"><a href="#7-2源代码" class="headerlink" title="7.2源代码"></a>7.2源代码</h2><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">cat</span><span class="params">(<span class="type">const</span> <span class="type">char</span> *dir)</span>&#123;</span><br><span class="line">    <span class="type">char</span> dir_name[<span class="number">32</span>];</span><br><span class="line">    <span class="type">char</span> dir_ext[<span class="number">32</span>];</span><br><span class="line">    <span class="type">char</span> *st;</span><br><span class="line">    st=<span class="built_in">strstr</span>(dir,<span class="string">&quot;.&quot;</span>);</span><br><span class="line">    <span class="keyword">if</span>(st==<span class="literal">NULL</span>)&#123;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;没有后缀，不是文件,请重新输入\n&quot;</span>);</span><br><span class="line">        <span class="keyword">return</span> ;</span><br><span class="line">    &#125;;</span><br><span class="line">    <span class="built_in">strcpy</span>(dir_ext,st+<span class="number">1</span>);</span><br><span class="line">    (*st)=<span class="string">&#x27;\0&#x27;</span>;</span><br><span class="line">    <span class="built_in">strcpy</span>(dir_name, dir);</span><br><span class="line">    <span class="comment">// int len=strlen(dir);</span></span><br><span class="line">    <span class="comment">// if(len&lt;7)dir_name[len]=&#x27; &#x27;;</span></span><br><span class="line">    <span class="keyword">if</span> (dir_name[<span class="number">0</span>] != <span class="string">&#x27;.&#x27;</span> || dir_name[<span class="number">1</span>] != <span class="string">&#x27;.&#x27;</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">// 进入当前目录子目录</span></span><br><span class="line">        <span class="comment">//  char **dirset=NULL;</span></span><br><span class="line">            <span class="type">int</span> clus;</span><br><span class="line">                <span class="comment">// 找到目标目录</span></span><br><span class="line">                <span class="keyword">if</span> (isroot)</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="comment">// 根目录特殊处理</span></span><br><span class="line">                    <span class="keyword">for</span> (<span class="type">int</span> j = <span class="number">16384</span>;; j += <span class="keyword">sizeof</span> fcb)</span><br><span class="line">                    &#123;</span><br><span class="line">                        disk_read(&amp;ftmp, j, <span class="keyword">sizeof</span> ftmp);</span><br><span class="line">                        <span class="type">int</span> k = <span class="number">0</span>;</span><br><span class="line">                        <span class="keyword">for</span> (k = <span class="number">0</span>; (ftmp.DIR_Name[k] != <span class="string">&#x27; &#x27;</span>&amp;&amp;ftmp.DIR_Name[k] != <span class="number">0</span>) &amp;&amp; k &lt; <span class="number">8</span>; k++)</span><br><span class="line">                        &#123;</span><br><span class="line">                        &#125;;</span><br><span class="line">                        ftmp.DIR_Name[k] = <span class="string">&#x27;\0&#x27;</span>;</span><br><span class="line">                        <span class="type">char</span> ext[<span class="number">32</span>];</span><br><span class="line">                        <span class="keyword">for</span>(<span class="type">int</span> h=<span class="number">0</span>;h&lt;<span class="number">3</span>;h++)&#123;</span><br><span class="line">                            <span class="keyword">if</span>(ftmp.DIR_Ext[h]==<span class="string">&#x27; &#x27;</span>||ftmp.DIR_Ext[h]==<span class="number">0</span>)&#123;</span><br><span class="line">                            ext[h]=<span class="string">&#x27;\0&#x27;</span>;    </span><br><span class="line">                                <span class="keyword">break</span>;</span><br><span class="line">                            &#125;</span><br><span class="line">                            ext[h]=ftmp.DIR_Ext[h];</span><br><span class="line">                        &#125;;</span><br><span class="line">                        <span class="keyword">if</span> (<span class="built_in">strcmp</span>(ftmp.DIR_Name, dir_name) == <span class="number">0</span>&amp;&amp;<span class="built_in">strcmp</span>(ext,dir_ext)==<span class="number">0</span>)</span><br><span class="line">                        &#123;</span><br><span class="line">                            <span class="comment">// 找到</span></span><br><span class="line">                            fatmp.f[<span class="number">0</span>] = ftmp.DIR_FstClus[<span class="number">0</span>];</span><br><span class="line">                            fatmp.f[<span class="number">1</span>] = ftmp.DIR_FstClus[<span class="number">1</span>];</span><br><span class="line">                            <span class="type">int</span> clus = read_cluster(fatmp, <span class="number">0</span>);</span><br><span class="line">                            <span class="type">int</span> index = ((clus - <span class="number">2</span>) * <span class="number">4</span> + <span class="number">64</span>) * <span class="number">512</span>;</span><br><span class="line">                            <span class="keyword">for</span>(<span class="type">int</span> l=index;;l++)&#123;</span><br><span class="line">                                    <span class="type">char</span> chr;</span><br><span class="line">                                    disk_read(&amp;chr,l,<span class="keyword">sizeof</span> chr);</span><br><span class="line">                                    <span class="keyword">if</span>(chr==<span class="number">0</span>)&#123;</span><br><span class="line">                                        <span class="built_in">printf</span>(<span class="string">&quot;\n&quot;</span>);</span><br><span class="line">                                        <span class="keyword">return</span> ;</span><br><span class="line">                                    &#125;</span><br><span class="line">                                    <span class="built_in">printf</span>(<span class="string">&quot;%c&quot;</span>,chr);</span><br><span class="line">                            &#125;</span><br><span class="line">                            <span class="keyword">return</span>;</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;;</span><br><span class="line">                    <span class="built_in">printf</span>(<span class="string">&quot;当前根目录没有此文件\n&quot;</span>);</span><br><span class="line">                    <span class="keyword">return</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">else</span></span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="comment">// 不是根目录，去数据去寻找</span></span><br><span class="line">                    fatmp.f[<span class="number">0</span>] = currdir.DIR_FstClus[<span class="number">0</span>];</span><br><span class="line">                    fatmp.f[<span class="number">1</span>] = currdir.DIR_FstClus[<span class="number">1</span>];</span><br><span class="line">                    clus = read_cluster(fatmp, <span class="number">0</span>);</span><br><span class="line">                    <span class="type">int</span> index = ((clus - <span class="number">2</span>) * <span class="number">4</span> + <span class="number">64</span>) * <span class="number">512</span>;</span><br><span class="line">                    <span class="keyword">for</span> (<span class="type">int</span> j = index;; j += <span class="keyword">sizeof</span> ftmp)</span><br><span class="line">                    &#123;</span><br><span class="line">                        disk_read(&amp;ftmp, j, <span class="keyword">sizeof</span> ftmp);</span><br><span class="line">                        <span class="type">int</span> k = <span class="number">0</span>;</span><br><span class="line">                        <span class="keyword">for</span> (k = <span class="number">0</span>; k &lt; <span class="number">8</span> &amp;&amp; ftmp.DIR_Name[k] != <span class="string">&#x27; &#x27;</span>; k++);</span><br><span class="line">                        ftmp.DIR_Name[k] = <span class="string">&#x27;\0&#x27;</span>;</span><br><span class="line">                        <span class="keyword">if</span> (<span class="built_in">strcmp</span>(ftmp.DIR_Name, dir_name) == <span class="number">0</span>)</span><br><span class="line">                        &#123;</span><br><span class="line">                            fatmp.f[<span class="number">0</span>] = ftmp.DIR_FstClus[<span class="number">0</span>];</span><br><span class="line">                            fatmp.f[<span class="number">1</span>] = ftmp.DIR_FstClus[<span class="number">1</span>];</span><br><span class="line">                            <span class="type">int</span> clus = read_cluster(fatmp, <span class="number">0</span>);</span><br><span class="line">                             index = ((clus - <span class="number">2</span>) * <span class="number">4</span> + <span class="number">64</span>) * <span class="number">512</span>;</span><br><span class="line">                            <span class="comment">// 找到目标文件FCB;</span></span><br><span class="line">                            <span class="keyword">for</span>(<span class="type">int</span> l=index;;l++)&#123;</span><br><span class="line">                                    <span class="type">char</span> chr;</span><br><span class="line">                                    disk_read(&amp;chr,l,<span class="keyword">sizeof</span> chr);</span><br><span class="line">                                    <span class="keyword">if</span>(chr==<span class="number">0</span>)&#123;</span><br><span class="line">                                        <span class="built_in">printf</span>(<span class="string">&quot;\n&quot;</span>);</span><br><span class="line">                                        <span class="keyword">return</span> ;</span><br><span class="line">                                    &#125;</span><br><span class="line">                                    <span class="built_in">printf</span>(<span class="string">&quot;%c&quot;</span>,chr);</span><br><span class="line">                            &#125;</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;当前目录下没有此文件\n&quot;</span>);</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="7-3测试"><a href="#7-3测试" class="headerlink" title="7.3测试"></a>7.3测试</h2><p>cat main.c</p>
<p><img src="/blog/img/image-20230623225853302.png" alt="image-20230623225853302"></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="https://gitee.com/lanceluot/blog.git/2024/04/30/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E5%AE%9E%E8%B7%B5-%E5%AE%9E%E7%8E%B0%E4%B8%80%E4%B8%AAfat12%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F/" data-id="clvmln00f0003kk5b4meehyd0" data-title="操作系统实践-实现一个fat12文件系统" class="article-share-link"><span class="fa fa-share">Teilen</span></a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/" rel="tag">操作系统</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/blog/2024/05/01/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%AE%9E%E9%AA%8C3-%E6%96%87%E4%BB%B6io%E7%BC%96%E7%A8%8B/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Neuer</strong>
      <div class="article-nav-title">
        
          嵌入式实验3-文件io编程
        
      </div>
    </a>
  
  
    <a href="/blog/2024/04/25/LambdaQuery-%E5%92%8C-Query%E7%9A%84%E5%8C%BA%E5%88%AB/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Älter</strong>
      <div class="article-nav-title">LambdaQuery 和 Query的区别</div>
    </a>
  
</nav>

  
</article>


</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Kategorien</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E8%AE%A1%E7%AE%97%E6%9C%BA/">计算机</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/BUG/" rel="tag">BUG</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/RPC/" rel="tag">RPC</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/git/" rel="tag">git</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/java/" rel="tag">java</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/java%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91/" rel="tag">java后端开发</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/java%E6%BA%90%E7%A0%81/" rel="tag">java源码</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/jvm/" rel="tag">jvm</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/leetcode/" rel="tag">leetcode</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/leetcode%E9%A2%98%E8%A7%A3/" rel="tag">leetcode题解</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/rabbitmq/" rel="tag">rabbitmq</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/redis/" rel="tag">redis</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/shell/" rel="tag">shell</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/spring/" rel="tag">spring</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/springboot/" rel="tag">springboot</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/test/" rel="tag">test</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E4%BD%9C%E4%B8%9A/" rel="tag">作业</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E5%AE%9E%E9%AA%8C/" rel="tag">实验</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E5%AE%9E%E9%AA%8C3/" rel="tag">实验3</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E6%84%9F%E6%83%B3/" rel="tag">感想</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/" rel="tag">操作系统</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/" rel="tag">数据结构与算法</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E6%B5%8B%E8%AF%95/" rel="tag">测试</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E7%96%91%E9%97%AE/" rel="tag">疑问</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E7%AC%94%E8%AE%B0/" rel="tag">笔记</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E7%AE%97%E6%B3%95/" rel="tag">算法</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/" rel="tag">设计模式</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E9%97%AE%E9%A2%98/" rel="tag">问题</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/blog/tags/BUG/" style="font-size: 10px;">BUG</a> <a href="/blog/tags/RPC/" style="font-size: 10px;">RPC</a> <a href="/blog/tags/git/" style="font-size: 10px;">git</a> <a href="/blog/tags/java/" style="font-size: 20px;">java</a> <a href="/blog/tags/java%E5%90%8E%E7%AB%AF%E5%BC%80%E5%8F%91/" style="font-size: 10px;">java后端开发</a> <a href="/blog/tags/java%E6%BA%90%E7%A0%81/" style="font-size: 10px;">java源码</a> <a href="/blog/tags/jvm/" style="font-size: 10px;">jvm</a> <a href="/blog/tags/leetcode/" style="font-size: 10px;">leetcode</a> <a href="/blog/tags/leetcode%E9%A2%98%E8%A7%A3/" style="font-size: 15px;">leetcode题解</a> <a href="/blog/tags/rabbitmq/" style="font-size: 10px;">rabbitmq</a> <a href="/blog/tags/redis/" style="font-size: 10px;">redis</a> <a href="/blog/tags/shell/" style="font-size: 10px;">shell</a> <a href="/blog/tags/spring/" style="font-size: 10px;">spring</a> <a href="/blog/tags/springboot/" style="font-size: 10px;">springboot</a> <a href="/blog/tags/test/" style="font-size: 10px;">test</a> <a href="/blog/tags/%E4%BD%9C%E4%B8%9A/" style="font-size: 10px;">作业</a> <a href="/blog/tags/%E5%AE%9E%E9%AA%8C/" style="font-size: 15px;">实验</a> <a href="/blog/tags/%E5%AE%9E%E9%AA%8C3/" style="font-size: 10px;">实验3</a> <a href="/blog/tags/%E6%84%9F%E6%83%B3/" style="font-size: 10px;">感想</a> <a href="/blog/tags/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/" style="font-size: 10px;">操作系统</a> <a href="/blog/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/" style="font-size: 10px;">数据结构与算法</a> <a href="/blog/tags/%E6%B5%8B%E8%AF%95/" style="font-size: 10px;">测试</a> <a href="/blog/tags/%E7%96%91%E9%97%AE/" style="font-size: 10px;">疑问</a> <a href="/blog/tags/%E7%AC%94%E8%AE%B0/" style="font-size: 10px;">笔记</a> <a href="/blog/tags/%E7%AE%97%E6%B3%95/" style="font-size: 10px;">算法</a> <a href="/blog/tags/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/" style="font-size: 15px;">设计模式</a> <a href="/blog/tags/%E9%97%AE%E9%A2%98/" style="font-size: 10px;">问题</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archiv</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2024/05/">May 2024</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2024/04/">April 2024</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2024/03/">March 2024</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2024/02/">February 2024</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2024/01/">January 2024</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2023/10/">October 2023</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2023/09/">September 2023</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2023/08/">August 2023</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2023/05/">May 2023</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2023/04/">April 2023</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2022/12/">December 2022</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">letzter Beitrag</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/blog/2024/05/01/%E7%AE%97%E6%B3%95%E8%AE%BE%E8%AE%A1%E4%B8%8E%E5%88%86%E6%9E%90%E5%AE%9E%E9%AA%8C%E4%B8%89-%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92/">算法设计与分析实验三-动态规划</a>
          </li>
        
          <li>
            <a href="/blog/2024/05/01/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%AE%9E%E9%AA%8C3-%E6%96%87%E4%BB%B6io%E7%BC%96%E7%A8%8B/">嵌入式实验3-文件io编程</a>
          </li>
        
          <li>
            <a href="/blog/2024/04/30/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E5%AE%9E%E8%B7%B5-%E5%AE%9E%E7%8E%B0%E4%B8%80%E4%B8%AAfat12%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F/">操作系统实践-实现一个fat12文件系统</a>
          </li>
        
          <li>
            <a href="/blog/2024/04/25/LambdaQuery-%E5%92%8C-Query%E7%9A%84%E5%8C%BA%E5%88%AB/">LambdaQuery 和 Query的区别</a>
          </li>
        
          <li>
            <a href="/blog/2024/04/25/LambdaQuery%E5%92%8CQuery%E7%9A%84%E5%8C%BA%E5%88%AB/">LambdaQuery和Query的区别</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2024 myself<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/blog/" class="mobile-nav-link">Home</a>
  
    <a href="/blog/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/blog/js/jquery-3.6.4.min.js"></script>



  
<script src="/blog/fancybox/jquery.fancybox.min.js"></script>




<script src="/blog/js/script.js"></script>





  </div>
</body>
</html>